/**
 * 在命令行输出对应命名空间的redux state
 * @param {string} namespace
 */
export function logModelState(namespace, expand = false) {
  try {
    console.log(namespace, ' model state:');
    if (expand) {
      // eslint-disable-next-line no-underscore-dangle
      console.log(JSON.stringify(window.g_app._store.getState()[namespace], null, 4));
    } else {
      // eslint-disable-next-line no-underscore-dangle
      console.log(JSON.parse(JSON.stringify(window.g_app._store.getState()[namespace])));
    }
  } catch (e) {
    console.error(e);
  }
}

/**
 *  在命令行输出对应model命名空间
 * @param {string} namespace
 */
export function logModel(namespace, expand = false) {
  try {
    console.log(namespace, ' model:');
    if (expand) {
      console.log(
        // eslint-disable-next-line no-underscore-dangle
        JSON.stringify(window.g_app._models.find(item => item.namespace === namespace), null, 4)
      );
    } else {
      // eslint-disable-next-line no-underscore-dangle
      console.log(window.g_app._models.find(item => item.namespace === namespace));
    }
  } catch (e) {
    console.error(e);
  }
}

try {
  // 非生产环境加入
  if (process.env.NODE_ENV !== 'production') {
    // 扩展到window.console对象上
    window.console.logModelState = logModelState;
    window.console.logModel = logModel;
  }
} catch (e) {
  console.error(e);
}

export default {};
